package com.ruoyi.project.task.ratify.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.person.info.domain.PersonInfo;
import com.ruoyi.project.task.mission.service.ITaskMissionService;
import com.ruoyi.project.task.postpone.domain.TaskPostpone;
import com.ruoyi.project.task.postpone.service.ITaskPostponeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Pathosis
 * @date 2020-09-19 10:10
 * @description:
 */
@Controller
@RequestMapping("/task/ratify")
public class RetifyController extends BaseController{
    @Autowired
    private ITaskPostponeService itps;

    @Autowired
    private ITaskMissionService itms;

    private String prefix = "task/ratify";


    @RequiresPermissions("task:ratify:view")
    @GetMapping
    public String toPostpone(){
        return prefix + "/ratify";
    }

    @RequiresPermissions("task:ratify:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskPostpone taskPostpone){
        startPage();

        List<TaskPostpone> list = itps.selectAllTaskPostpone(taskPostpone);

        return getDataTable(list);
    }

    @GetMapping("/edit/{postponeId}")
    public String edit(@PathVariable("postponeId") Long postponeId, ModelMap mmap)
    {
        //查询出所有的员工
        List<PersonInfo> personInfos = itms.selectAllPerson();
        mmap.addAttribute("list",personInfos );
        mmap.addAttribute("taskPostpone", itps.selectTaskPostponeById(postponeId));
        return prefix + "/edit";
    }

    @RequiresPermissions("task:ratify:edit")
    @Log(title = "任务延期管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated TaskPostpone taskPostpone) {
        return toAjax(itps.updateTaskPostpone(taskPostpone));
    }

}
